package org.example.app.model;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Generated;
import lombok.NoArgsConstructor;
import org.example.app.web.vm.UserVm;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "user")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) //缓存
public class User implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) //自增
    private Integer id;

    @Column(name = "add_time")
    private LocalDateTime addTime = LocalDateTime.now();

    @Column(name = "update_time")
    private LocalDateTime updateTime = LocalDateTime.now();

    @Column
    private String username;

    @Column
    private String password;

    @Column
    private String realname;

    @Column
    private Integer count = 0;

    @Column
    private String email;

    @Override
    public String toString() {
        return "用户名： " +  username + ", 真实姓名: " + realname + ", 创建时间: " + addTime + ", 更新时间: " + updateTime + "\n";
    }


    public User (UserVm userVm) {
        this.username = userVm.getUsername();
        this.realname = userVm.getRealname();
        this.password = userVm.getPassword();
        this.email = userVm.getEmail();
    }
}
